package com.whenjun.service.impl;

import com.ifootbook.util.Util;
import com.whenjun.entity.AccessLog;
import com.whenjun.mapper.AccessLogMapper;
import com.whenjun.service.IAccessLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whenjun.util.SaTokenUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whenjun
 * @since 2023-11-08
 */
@Service
public class AccessLogServiceImpl extends ServiceImpl<AccessLogMapper, AccessLog> implements IAccessLogService {

    @Transactional
    public void addLog(String log) {
        try {
            String accountId = SaTokenUtil.getUserId();

            LocalDateTime dateTime = LocalDateTime.now();

            String id = Util.getUUID32();

            AccessLog accessLog = new AccessLog();
            accessLog.setId(id);
            accessLog.setLogContent(log);
            accessLog.setAccountId(accountId);
            accessLog.setCreateTime(dateTime);

            getBaseMapper().insert(accessLog);
        }catch (Exception e) {

        }
    }
}
